Learn ✔
- Introduction to Bits and Tricks
- Check if the i-th bit is Set or Not
- 14 March, 2026: 00.01.26 ✔
- 19 March, 2026: 00.01.12 ✔
- Check if a Number is Odd or Not
- 12 March, 2026: 00.01.44 ❌
- Intitution is right.
- Couldn't able to implement it.
- 19 March, 2026: 00.01.58 ✔
- Put the braces properly
- 12 March, 2026: 00.01.44 ❌
- Check if a Number is Power of 4 or Not
- 14 March, 2026: 00.07.41 ❌
- Failed at edge cases
- 19 March, 2026: 00.04.05 ✔
- Put the braces properly
- 14 March, 2026: 00.07.41 ❌
- Count the Number of Set Bits
- 14 March, 2026: 00.22.46 ❌
- Failed at optimization
- 19 March, 2026: 00.09.16 ❌
- Failed at cycle counting
- 14 March, 2026: 00.22.46 ❌
- Set/Unset the rightmost unset bit
- 14 March, 2026: 00.00.00 ❌
- Failed at implementation
- Intitution is right.
- 19 March, 2026: 00.01.12 ✔
- 14 March, 2026: 00.00.00 ❌
- Swap Two Numbers
- 13 March, 2026: 00.00.00 ❌
- Failed at implementation
- 19 March, 2026: 00.02.13 ✔
- 13 March, 2026: 00.00.00 ❌
- Divide two numbers without multiplication and division
-
14 March, 2026: 00.00.00 ❌
- Failed at implementation
-
19 March, 2026: 00.12.06 ❌
- Failed at Optimization
Bruteforce
-
Handle the edge cases first.
-
XOR operator is used to determine the sign of the result.
-
Handle the overflow when taking absolute values using
llabs().abs(INT_MIN)causes integer overflow becauseINT_MAX = 2^31 - 1.Even though you declared
xandyaslong long,abs(dividend)is computed as anintbefore being assigned tolong long. This can result in undefined behavior.Fix: Use
long longbefore callingabs:long long x = llabs((long long)dividend);
long long y = llabs((long long)divisor);
Optimization
- Instead of subtracting
yone by one, - Double
yeach time until it becomes larger thanx.
-